import request from '@/config/axios'

// 网格 VO
export interface GridVO {
  id: number // ID
  name: string // 网格名称
  provinceId: number // 省份
  cityId: number // 城市
  provinceName: string // 省份
  cityName: string // 城市
}
export interface AssignUserGridRespVO {
  gridId: number // ID
  userIds: number[]
}

// 网格 API
export const GridApi = {
  // 查询网格分页
  getGridPage: async (params: any) => {
    return await request.get({ url: `/envir/grid/page`, params })
  },

  // 查询网格详情
  getGrid: async (id: number) => {
    return await request.get({ url: `/envir/grid/get?id=` + id })
  },

  // 新增网格
  createGrid: async (data: GridVO) => {
    return await request.post({ url: `/envir/grid/create`, data })
  },

  // 修改网格
  updateGrid: async (data: GridVO) => {
    return await request.put({ url: `/envir/grid/update`, data })
  },

  // 删除网格
  deleteGrid: async (id: number) => {
    return await request.delete({ url: `/envir/grid/delete?id=` + id })
  },

  // 导出网格 Excel
  exportGrid: async (params) => {
    return await request.download({ url: `/envir/grid/export-excel`, params })
  },

  // 获得网格下用户列表
  listGridUsers: async (gridId: number) => {
    return await request.get({ url: `/envir/grid/list-grid-users?gridId=${gridId}` })
  },

  // 设置网格用户
  assignGridUser: async (data: AssignUserGridRespVO) => {
    return await request.post({ url: `/envir/grid/assign-grid-user`, data })
  },

  getSimpleList: async () => {
    return await request.get({ url: `/envir/grid/simple-list` })
  }
}